package work3.work2;

import Uti.ScannerUti;

import java.util.ArrayList;

public class PrimeDetermination {
    ArrayList<Thread> list = new ArrayList<>();

    public PrimeDetermination() {
        System.out.println("请输入10个大数（超过12位的整数）");
        for (int i = 0; i < 10; i++) {
            double t = 0;
            while (true) {
                t = ScannerUti.getDouble();
                if (Math.log10(t) > 11) break;
            }
            Double f = t;
            Thread tt = new Thread(new Runnable() {
                @Override
                public void run() {
                    int flag = 1;
                    for (int j = 100000; j <= Math.sqrt(f); j++) {
                        if (f % j == 0) {
                            System.out.println(f + "不是素数");
                            flag = 0;
                        }
                    }
                    if (flag == 1) {
                        System.out.println(f + "是素数");
                    }
                }
            });
            list.add(tt);
        }
        System.out.println("元神!启动");
        starts();

    }

    void starts() {
        for (Thread s : list) {
            s.start();
            try {
                s.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }


}
